from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `admin_login_log` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `user_id` INT NOT NULL,
    `ip` VARCHAR(255) NOT NULL,
    `url` VARCHAR(255) NOT NULL COMMENT '请求地址',
    `request_id` VARCHAR(64) NOT NULL COMMENT '请求ID',
    `form` LONGTEXT COMMENT '请求参数',
    `cost_time` DOUBLE COMMENT '耗时',
    `browser` VARCHAR(255) COMMENT '浏览器',
    `system` VARCHAR(255) COMMENT '系统',
    `status` INT NOT NULL COMMENT '状态' DEFAULT 1,
    `country` VARCHAR(64) COMMENT '国家',
    `region` VARCHAR(64) COMMENT '大区',
    `province` VARCHAR(64) COMMENT '省份',
    `city` VARCHAR(64) COMMENT '城市',
    `isp` VARCHAR(128) COMMENT '运营商',
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6)
) CHARACTER SET utf8mb4 COMMENT='管理员登录日志';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS `admin_login_log`;"""
